package br.usp.ime.origami.util;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.Scanner;

import org.apache.log4j.Logger;

import br.usp.ime.origami.model.SimplePoint;
import br.usp.ime.origami.model.SimplePolygon;

public class PolygonReader {

	private static final Logger logger = Logger.getLogger(PolygonReader.class);

	public static SimplePolygon getPolygon(InputStream stream) {
		Scanner scanner = new Scanner(stream);
		scanner.useDelimiter("\\s+");

		SimplePolygon polygon = new SimplePolygon();
		while (scanner.hasNextDouble()) {
			SimplePoint p = new SimplePoint(scanner.nextDouble(), scanner.nextDouble());
			polygon.add(p);
			logger.debug(p);
		}

		return polygon;
	}

	public static void main(String[] args) throws FileNotFoundException {
		System.out.println(getPolygon(new FileInputStream("polygons/rectangle.polygon")));
	}
}
